(ns socialsite.templates
  (:use net.cgrand.enlive-html)
  (:use 
        net.cgrand.moustache
        ring.util.response
        ring.adapter.jetty
        [ring.middleware file params reload session]))

(deftemplate page "socialsite/page.html" [session styles scripts cnt]
  [:link.style]   (clone-for [style styles]
                    (set-attr :href style))
  [:script.import] (clone-for [script scripts]
                    (set-attr :src script))
  [:a#loginout]   (content
                   (if (seq (:nick session))
                     {:tag :a, :attrs {:href "/logout"}, :content ["logout"]}
                     {:tag :a, :attrs {:href "/login"}, :content ["login"]}))
  [:div#content]  (content cnt))

(defn view-frontpage
  [r]
  (->> (page (:session r) nil nil "Welcome")
       response))

(def routes
  (app
   (wrap-file "src/main/resources")
   [""] view-frontpage))

(doto (Thread. #(run-jetty #'routes {:port 8080})) .start)

